package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.UserData;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.po.MarketUser;
import com.cskaoyan.bean.usersadmin.*;
import com.cskaoyan.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author bruce
 * @date 2022/06/02 20:41
 */
@RestController
@RequestMapping("admin")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    AddressService addressService;

    @Autowired
    CollectService collectService;

    @Autowired
    FootprintService footprintService;

    @Autowired
    SearchHistoryService searchHistoryService;

    @Autowired
    FeedbackService feedbackService;

    @Autowired
    DashBoardService dashBoardService;

    @RequestMapping("user/list")
    //public BaseRespVo list(Integer page,Integer limit,String sort,String order,String username) {
    public BaseRespVo userList(BaseParam param, String username, String moblie, Integer userId) {
        UserData userData = userService.query(param, username, moblie, userId);
        return BaseRespVo.ok(userData);
    }

    @Transactional
    @RequestMapping("user/update")
    public BaseRespVo userupdate(@RequestBody MarketUser marketUser) {
        userService.update(marketUser);
        return BaseRespVo.ok();
    }

    @RequestMapping("user/detail")
    public BaseRespVo userById(Integer id) {
        MarketUser marketUser = userService.queryById(id);
        return BaseRespVo.ok(marketUser);
    }

    @RequestMapping("address/list")
    public BaseRespVo addressList(BaseParam param, String name, Integer userId) {
        AddressData addressData = addressService.query(param, name, userId);
        return BaseRespVo.ok(addressData);
    }

    @RequestMapping("collect/list")
    public BaseRespVo collectList(BaseParam param, Integer userId, Integer valueId) {
        CollectData collectData = collectService.query(param, userId, valueId);
        return BaseRespVo.ok(collectData);
    }

    @RequestMapping("footprint/list")
    public BaseRespVo footprintList(BaseParam param, Integer userId, Integer goodsId) {
        FootprintData footprintData = footprintService.query(param, userId, goodsId);
        return BaseRespVo.ok(footprintData);
    }

    @RequestMapping("history/list")
    public BaseRespVo historyList(BaseParam param, Integer userId, String keyword) {
        SearchHistoryData searchHistoryData = searchHistoryService.query(param, userId, keyword);
        return BaseRespVo.ok(searchHistoryData);
    }

    @RequestMapping("feedback/list")
    public BaseRespVo feedbackList(BaseParam param, String username, Integer id) {
        //todo
        FeedbackData feedbackData = feedbackService.query(param, username, id);
        return BaseRespVo.ok(feedbackData);
    }

    @RequestMapping("dashboard")
    public BaseRespVo dashboard() {
        DashBoardData dashBoardData = dashBoardService.query();
        return BaseRespVo.ok(dashBoardData);
    }
}
